package view;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

import model.BlockInterface;

public class SonarView implements View 
{

	@Override
	public void show(BlockInterface[][] table, int n) 
	{
		int cx = 0, cy = 0;
		BufferedReader buff = new BufferedReader(new InputStreamReader(System.in));
		System.out.println("Coordonata Orizontala (cx):= ");
		try {
			cx = Integer.parseInt(buff.readLine());
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		System.out.println("Coordonata Verticala (cy):= ");
		try {
			cy = Integer.parseInt(buff.readLine());
		} catch (NumberFormatException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
			int i,j;
			System.out.print("  ");
			for(i=1;i<=n;i++)
				System.out.print(" "+i+" ");
			System.out.println(" ");
			for(i=1;i<=n;i++)
			{
				System.out.print(i+" ");
				if(i == cx-2 || i == cx+2)
					for(j=1;j<=n;j++)
					{
						if(j == cy)
							if(table[i-1][j-1]!=null)
								System.out.print(" "+table[i-1][j-1].toString()+" ");
							else
								System.out.print(" - ");
						else
							System.out.print("   ");
					}
				else
					if(i == cx-1 || i == cx+1)
						for(j=1;j<=n;j++)
						{
							if(j == cy-1 || j == cy || j== cy+1)
								if(table[i-1][j-1]!=null)
									System.out.print(" "+table[i-1][j-1].toString()+" ");
								else
									System.out.print(" - ");
							else
								System.out.print("   ");
						}
					else
					{
						if(i == cx)
							for(j=1;j<=n;j++)
							{
								if(j == cy-2 || j == cy-1 || j == cy || j== cy+1 || j == cy+2)
									if(table[i-1][j-1]!=null)
										System.out.print(" "+table[i-1][j-1].toString()+" ");
									else
										System.out.print(" - ");
								else
									System.out.print("   ");
							}
					}
				System.out.println(" ");
			}
			System.out.println("LEGENDA: ");
			System.out.println("  * - parte lovita dintr-o nava\n  x - bloc intreg al unei nave");
	}

}
